import React from 'react'
import './login.less'
import { Button, Checkbox, Form, Input,notification } from 'antd';
import $axios from '../utils/axios';
import {useNavigate} from 'react-router-dom'



const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo);
};

export default function Login() {
  let $router=useNavigate()


  const onFinish = (values: any) => {
    console.log('Success:', values);
    $axios({
      url:'/api/chcsLogin',
      method:'post',
      data:{account:values.account,pwd:values.pwd}
    }).then((res:any)=>{
       localStorage.setItem('医生data',res.data)
       notification.open({
        message: res.msg,
        duration:1,
      });
      if(res.code==200){
          setTimeout(()=>{
            $router('/home')
          },1000)
      }
    })
  };
  return (
    <div className='login' >
      <div className='max'>
        <div className='left'>
          <span>家庭医生后台管理系统</span>
          <img src="https://cdn7.axureshop.com/demo/1881228/images/%E7%99%BB%E5%BD%95/u1111.png" alt="" />
        </div>
        <div className='right'>
          <div className='form'>
            <img src="https://cdn7.axureshop.com/demo/1881228/images/%E7%BB%84%E4%BB%B6_%E8%A7%84%E8%8C%83/u408.jpg" alt="" />
            <h3>欢迎登录</h3>
            <Form
              name="basic"
              wrapperCol={{ span: 100 }}
              style={{ maxWidth: 700 }}
              initialValues={{ remember: true }}
              onFinish={onFinish}
              onFinishFailed={onFinishFailed}
              autoComplete="off"
            >
              <Form.Item
                name="account"

                rules={[{ required: true, message: 'Please input your username!' }]}
              >
                <Input placeholder="请输入手机号码" style={{ height: '40px' }} />
              </Form.Item>

              <Form.Item
                name="pwd"
                rules={[{ required: true, message: 'Please input your password!' }]}
              >
                <Input.Password style={{ height: '40px' ,width:'100%'}} placeholder="请输入密码" />
              </Form.Item>

              <Form.Item name="remember" valuePropName="checked" wrapperCol={{ offset: 0, span: 30 }}>
                <Checkbox>我已经阅读并同意 <a href="#">《用户隐私政策》</a> </Checkbox>
              </Form.Item>

              <Form.Item wrapperCol={{ offset: 0, span: 16 }}>
                <Button type="primary" htmlType="submit" style={{ width: '360px', height: '45px' }}>
                  登录
                </Button>
              </Form.Item>
            </Form>
          </div>
        </div>
      </div>
    </div>
  )
}
